Skip to content

fix: Improved OnValueChanged door example#3959

Open
NoelStephensUnity wants to merge 9 commits intodevelop-2.0.0from
fix/docs/onvaluechange_example_update
Open

fix: Improved OnValueChanged door example#3959
NoelStephensUnity wants to merge 9 commits intodevelop-2.0.0from
fix/docs/onvaluechange_example_update

Conversation

@NoelStephensUnity
Copy link
Copy Markdown
Member

@NoelStephensUnity NoelStephensUnity commented Apr 27, 2026

Purpose of this PR

Updating the door example to provide a more recommended way of using OnValueChanged and how to update based on changes in state/value. The original door example could lead users to believe that OnValueChanged would be invoked on all clients upon spawn.

Jira ticket

MTT-14954

Changelog

NA

Documentation

  • Includes updates to existing documentation.

Testing & QA (How your changes can be verified during release Playtest)

Functional Testing

Manual testing :

  • Manual testing done
    • Reading over the change in documentation.

Automated tests:

  • Covered by existing automated tests
  • Covered by new automated tests

Does the change require QA team to:

  • Review automated tests?
  • Execute manual tests?
  • Provide feedback about the PR?

If any boxes above are checked the QA team will be automatically added as a PR reviewer.

Backports

Does not require a backport.

@NoelStephensUnity NoelStephensUnity marked this pull request as ready for review May 1, 2026 18:41
removing trailing spaces.
Fixes to the example script
Did another pass over this script with some improvements.
removing trailing whitespace
Copy link
Copy Markdown
Contributor

@jabbacakes jabbacakes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basic tweaks to the commentary in the code sample, nothing major

public DoorStates CurrentState => m_State.Value;

/// <summary>
/// Invoked while the <see cref="NetworkObject"/> is in the middle of
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Invoked while the <see cref="NetworkObject"/> is in the middle of
/// Invoked while the <see cref="NetworkObject"/> is in the process of

public override void OnNetworkSpawn()
{
State.OnValueChanged += OnStateChanged;
// The write authority (server) does not need to know about its
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// The write authority (server) does not need to know about its
// The write authority (server) doesn't need to know about its

{
State.OnValueChanged += OnStateChanged;
// The write authority (server) does not need to know about its
// own changes (for this example) since it is the "single point
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// own changes (for this example) since it is the "single point
// own changes (for this example) since it's the "single point

protected override void OnNetworkPostSpawn()
{
// Everyone updates their door state when finished spawning the door
// in order to assure the door reflects (visually) its current state.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// in order to assure the door reflects (visually) its current state.
// to ensure the door reflects (visually) its current state.

// in order to assure the door reflects (visually) its current state.
UpdateFromState();

// Begin to start updating this NetworkBehaviour instance once all
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Begin to start updating this NetworkBehaviour instance once all
// Begin updating this NetworkBehaviour instance once all

}

/// <summary>
/// Invoked just before this instance runs through its de-spawn
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Invoked just before this instance runs through its de-spawn
/// Invoked just before this instance runs through its despawn

}

// Stop updating this NetworkBehaviour instance prior to running
// through the de-spawn process.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// through the de-spawn process.
// through the despawn process.

/// </summary>
/// <remarks>
/// When the previous state equals the current state, we are a client
/// that is doing its 1st synchronization of this door instance.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// that is doing its 1st synchronization of this door instance.
/// that is doing its first synchronization of this door instance.

}

/// <summary>
/// Invoke when the state is updated in order to apply the change
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Invoke when the state is updated in order to apply the change
/// Invoke when the state is updated to apply the change


public void OnStateChanged(bool previous, bool current)
/// <summary>
/// Invoked by either a Host or clients to interact with the door.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Invoked by either a Host or clients to interact with the door.
/// Invoked by either a host or clients to interact with the door.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants